<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            margin: 0;
            padding: 0;
        }
        #div1{
            width: 100px;
            height: 100px;
            background: red;
            position: absolute;
            left:0;
        }
        #div2{
            width: 1px;
            height: 300px;
            position: absolute;
            left: 300px;
            background: #000;
        }
    </style>
</head>
<body>
  <button id="btn" onclick="startMove()">开始运动</button>
  <div id="div1"></div>
  <div id="div2"></div>

  <script>
      var oDiv = document.getElementById('div1');
      var oBtn = document.getElementById('btn');

      function startMove() {
          setInterval(function () {
              var speed = (300-oDiv.offsetLeft)/10;
              speed = speed>0?Math.ceil(speed):Math.floor(speed);

              oDiv.style.left = oDiv.offsetLeft+speed+'px';
              document.title = oDiv.offsetLeft+','+speed;

          },30)
      }

  </script>
</body>
</html>